<template>
  <div class="login-container">

      <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="图片名称" width="80" />

      <el-table-column prop="imageUrl" label="图片地址" />

      <el-table-column prop="linkUrl" label="链接地址" />

      <el-table-column prop="gmtCreate" label="添加时间" width="160"/>

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/banner/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeBanner(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      background
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout=" prev, pager, next"
      @current-change="getList"
    />

  </div>
</template>

<script>
import banner from '@/api/edu/banner'
export default {
    
    data(){
        return{
            list:null,
            page:1,
            limit:5,
            total:0
        }
    },
    created(){
      this.getList();
    },
    methods:{
        getList(page=1){
            this.page=page;
            banner.pageBanner(this.page,this.limit)
            .then(response=>{
               this.list=response.data.items;
               this.total=response.data.total;
            })
        },
       
        removeBanner(id){
            this.$confirm('此操作将永久删除该幻灯片, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                banner.deleteBanner(id)
                .then(response=>{
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                     })
                     this.getList()
                })
                
            })
        }
    }
}
</script>